package com.forum.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.forum.demo.model.Article;
import com.forum.demo.model.response.ArticleResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    @Select("select avatar_url,nickname,article.id,board_id,user_id," +
            "title,visit_count,reply_count,like_count," +
            "article.state,article.create_time,article.update_time\n" +
            "from article, user_info\n" +
            "where article.user_id = user_info.id\n" +
            "and article.delete_state = 0\n" +
            "order by article.create_time desc\n" +
            "limit 0, 100")
    public List<ArticleResponse> selectArticleAndUser();

    @Select("select avatar_url,nickname,article.id,board_id,user_id," +
            "title,visit_count,reply_count,like_count,article.state," +
            "article.create_time,article.update_time\n" +
            "from article, user_info\n" +
            "where article.user_id = user_info.id\n" +
            "and article.delete_state = 0\n" +
            "and board_id = #{boardId}\n" +
            "order by article.create_time desc\n" +
            "limit 0, 100")
    public List<ArticleResponse> selectArticleAndUserByBoardId(Long boardId);

    @Select("select avatar_url,nickname,article.id,board_id,user_id,title,visit_count,reply_count,content,\n" +
            "like_count,article.state,article.create_time,article.update_time,name\n" +
            "from article, user_info,board\n" +
            "where article.user_id = user_info.id\n" +
            "and article.board_id = board.id\n" +
            "and article.delete_state = 0\n" +
            "and article.id = #{articleId}\n" +
            "order by article.create_time desc\n" +
            "limit 0, 100")
    public ArticleResponse selectArticleAndUserByArticleId(Long articleId);
}
